<template>
  <div>
    <van-nav-bar
      title="收货地址"
      left-text="返回"
      left-arrow
      @click-left="onClickLeft"
    />
    <van-address-list
      v-model="chosenAddressId"
      :list="item"
      default-tag-text="默认"
      @add="onAdd"
      @edit="onEdit"
    />
  </div>
</template>

<script>
import { Toast } from 'vant';
import { addressForm } from "../api";
import axios from 'axios';

export default {
  data() {
    return {
      item: [],     
      chosenAddressId: '1',
    }
  },
  methods: {
    onClickLeft() {
      this.$router.go(-1);
    },
    onAdd() {
      this.$router.push("/address");
    },
    onEdit(item, index) {
      let id = this.list[index].id;
      this.$router.push(`address?id=${id}`);
    }
  },
  created() {
     addressForm({username: localStorage.getItem('username')})
      .then(res =>{
          console.log(res);
          this.item = res.data;
      })
       .catch( (error) => {
        console.log(error);
      });
  }
};
</script>

<style>
</style>